package com.ddwl.message.domain.sms.enums;


import java.util.HashMap;
import java.util.Map;

/**
 * 短信发送渠道
 */
public enum SmsChannelEnum {

    tencent("tencent","tencentSmsServer","腾讯短信渠道"),

    ;
    /**
     * 渠道code
     */
    private String channel;
    /**
     * 渠道实现bean名称
     */
    private String beanName;
    /**
     * 渠道名称
     */
    private String name;

    SmsChannelEnum(String channel, String beanName, String name) {
        this.channel = channel;
        this.beanName = beanName;
        this.name = name;
    }

    public String getChannel() {
        return channel;
    }
    public String getBeanName() {
        return beanName;
    }
    public String getName() {
        return name;
    }

    /**
     * 根据渠道名获取实现bean名字
     * @return
     */
    public static String getChannelBeanName(String channel) {
        for (SmsChannelEnum smsChannel : values()) {
            if(smsChannel.getChannel().equals(channel)) {
                return smsChannel.getBeanName();
            }
        }
        return SmsChannelEnum.tencent.getBeanName();
    }

    /**
     * 根据渠道名获取短信渠道信息
     * @return
     */
    public static SmsChannelEnum getChannel(String channel) {
        for (SmsChannelEnum smsChannel : values()) {
            if(smsChannel.getChannel().equals(channel)) {
                return smsChannel;
            }
        }
        return null;
    }

    /**
     * 获取短信渠道
     * @return
     */
    public static Map<String,String> getChannelNames() {
        Map<String,String> map = new HashMap<>();
        for (SmsChannelEnum smsChannel : values()) {
            map.put(smsChannel.getChannel(),smsChannel.getName());
        }
        return map;
    }
}
